//index.js
//获取应用实例
const app = getApp()
const datas = require("../../data/driverMockData.js");
var handler = require("../../utils/function.js"),
tcity = require("../../data/citys.js"),
api = require("../../api.js"),
WxParse = require('../../wxParse/wxParse.js');
Page({
    data: {
        Img: handler.driverImg,
        addressName: null,
        avatar: "../../../images/driver/icon-02.png",
        activityList: [],
        orderCount: 0,
        currentTime: null,
        income: 0.00,
        reminder: "今日周一，无限号通知，多云25-30，事宜短袖。每日6点会更新数据信息。新的一天，不要忘记微笑哦。",
        name: "",
        orderCount: 0,
        income: 0.00,
        evaluate: [],
        myTask: [],
        // handler: [],
        serverPhone: "",
        left: 700,
        is_false: false,
        remind: '',
        way: 0,
    },
    onLoad: function() {
        setInterval(this.timeTask, 1000);
    },
    // 时间定时器
    timeTask: function() {
        const date = new Date();
        this.setData({
            currentTime: {
                h: date.getHours(),
                m: date.getMinutes()
            }
        });
    },
    onShow: function() {
        let that=this;
        handler.getLatLntHandler((res) => {
          console.log(res,'222222222');
          that.setData({
            addressName: res.startAddress.address, //开始位置
          })
        });
        this.setDataHandler();
        this.getDataHnadler();
    },
    getDataHnadler: function() {
        var that = this;
      var _this = this;
        app.request({
            url: api.driver.index,
            method: 'post',
            data: {},
            success: function(rs) {
                if (rs.data.is_complete == 0) {
                  wx.redirectTo({
                    url: '../../../../driver/personalInformation/personalInformation',
                  })
                }
              var announcement = rs.data.announcement;
              for (var i = 0; i < rs.data.announcement.length;i++){
                WxParse.wxParse('article', 'html', announcement[i].content, _this, 5)
              }
                that.setData({
                    orderCount: rs.data.Todayorder,
                    income: rs.data.income,
                    remind: rs.data.remind,
                    activityList: rs.data.announcement,
                    is_false: rs.data.reward,
                    way: rs.data.way,
                })
                wx.setStorageSync("customer", rs.data.customer);
            }
        })
    },
    // setDataHandler 渲染数据函数
    setDataHandler: function() {
        const avatar = wx.getStorageSync("userMessage") !== "" ? wx.getStorageSync("userMessage").avatar : "../../../images/icon/icon-02.png";
        const name = wx.getStorageSync("userMessage") !== "" ? wx.getStorageSync("userMessage").username : "";
        this.setData({
            avatar,
            evaluate: wx.getStorageSync("evaluate").length,
            name
        });
    },
    // intoPageHandler 页面跳转
    intoPageHandler: function(e) {
        // console.log(e.currentTarget.dataset.skip);
        handler.intoPageHandler(e.currentTarget.dataset.skip)
    },
    // callPhoneHandler 打电话功能
    callPhoneHandler: function() {
        handler.callPhoneHandler(wx.getStorageSync("serverphone"))
    },
    // intoPersonCenterHandler 个人中心
    intoPersonCenterHandler: function() {
        handler.intoPageHandler('../driver/personalCenter/personalCenter')
    },
    // getOrderHandler 开始抢单
    getOrderHandler: function(e) {
        if (e.currentTarget.dataset.way == 1) {
            wx.showToast({
                title: '听单方式为指派接单',
                icon:'none',
                duration: 1000,
            })
        } else {
            const orderStatus = wx.getStorageSync("setup");
            console.log('抢单', orderStatus)
            //if (orderStatus.listenWay === "抢单模式" && (orderStatus.orderHobby == "全部" || orderStatus.orderHobby == "实时")) {
            wx.navigateTo({
              url: '../driverOrder/getOrder/getOrder',
            })
            /* } else if (orderStatus.listenWay === "抢单模式" && orderStatus.orderHobby == "预约") {
                 handler.intoPageHandler('../driverOrder/appointmentOrder/appointmentOrder')
             }*/
        }
    },
})